package com.shop.Control;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringBufferInputStream;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.shop.util.BeanUtil;
import com.shop.util.FileUploadUtil;
import com.shop.util.FormAjaxUtil;
/**
 * 
 * <b>店铺管理原上传商品信息之图片上传<b>
 * @author 威 
 * <br>2017年12 
 *
 */
public class UploadImageAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	
	private InputStream inputStream;

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	
	private File file; 
	private String fileFileName;
	private String fileContentType;
	private String callbackObj;
	private String goodsId;
	
	public String getCallbackObj() {
		return callbackObj;
	}

	public void setCallbackObj(String callbackObj) {
		this.callbackObj = callbackObj;
	}

	public void setFile(File file){
		this.file = file;
	}
	public File getFile(){
		return file;
	}
	
	public void setFileFileName(String fileFileName){
		this.fileFileName = fileFileName;
	}
	public String getFileFileName(){
		return fileFileName;
	}
	
	public void setFileContentType(String fileContentType){
		this.fileContentType = fileContentType;
	}
	public String getFileContentType(){
		return fileContentType;
	}
	
	
	public String getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(String goodsId) {
		this.goodsId = goodsId;
	}

	@SuppressWarnings({"deprecation" })
	public String execute() {
		FileUploadUtil upload = (FileUploadUtil) BeanUtil.getBean("fileUploadUtil");
		String uploadPath = ServletActionContext.
				getServletContext().getRealPath("/upload");
		try {
			upload.wirteTo(file, uploadPath, fileFileName);
			inputStream = new StringBufferInputStream(
					FormAjaxUtil.successAccess(callbackObj, "upload/"+fileFileName));
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("返回异常数据");
			inputStream = new StringBufferInputStream(
					FormAjaxUtil.failAccess(callbackObj, "服务器异常"));
		}
		return SUCCESS;
	}
}
